package com.ftg.learn.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 我们自已定义的报文  响应报文
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/9/9 上午8:47
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value="自定义响应报文")
public class RespMessUtil<E> {

    /**
     * 状态码
     */
    @ApiModelProperty(value = "状态码",required = true)
    private Integer code;

    /**
     * 提示信息
     */
    @ApiModelProperty(value = "提示信息",required = true)
    private String mess;

    /**
     * 影响结果
     */
    private E data;

    /**
     * fdsfadsfsa
     *
     * @param codeStatus sfdsafd
     * @param data f  fdsafds
     * @param <E>  fdasfdsafdsfd
     * @return 1
     */
    public static <E> RespMessUtil<E> build(CodeStatusEnum codeStatus, E data) {
        RespMessUtil<E> respMess = new RespMessUtil<>();
        respMess.setCode(codeStatus.getCode());
        respMess.setMess(codeStatus.getDesc());
        respMess.setData(data);
        return respMess;
    }

    public static RespMessUtil<Integer> insertOk() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.SUCCESS.getCode());
        respMess.setMess(ConstUtil.TIP_INSERT_SUCCESS);
        respMess.setData(1);
        return respMess;
    }

    public static RespMessUtil<Integer> insertFailure() {
        RespMessUtil<Integer> respMess = new RespMessUtil<>();
        respMess.setCode(CodeStatusEnum.FAILURE.getCode());
        respMess.setMess(CodeStatusEnum.FAILURE.getDesc());
        return respMess;
    }

    public static <E> RespMessUtil<E> build(CodeStatusEnum codeStatus, String mess) {
        RespMessUtil<E> respMess = new RespMessUtil<>();
        respMess.setCode(codeStatus.getCode());
        respMess.setMess(mess);
        return respMess;
    }


}
